﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.protocolquotainfo
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    lcs.BLL.materialtypeinfo bm = new BLL.materialtypeinfo();
                    ddltype.DataSource = bm.GetAllList().Tables[0];
                    ddltype.DataTextField = "mtname";
                    ddltype.DataValueField = "mtid";
                    ddltype.DataBind();
                    int pqid = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(pqid);
                }
            }
        }

        private void ShowInfo(int pqid)
        {
            lcs.BLL.protocolquotainfo bll = new lcs.BLL.protocolquotainfo();
            lcs.Model.protocolquotainfo model = bll.GetModel(pqid);
           
            ddltype.SelectedValue = model.mtid.ToString();
            
            this.txtquota.Text = model.quota.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                string strErr = "";
                if (!PageValidate.IsDecimal(txtquota.Text))
                {
                    strErr += "配额格式错误！\\n";
                }

                if (strErr != "")
                {
                    MessageBox.Show(this, strErr);
                    return;
                }
                int pqid = (Convert.ToInt32(Request.Params["id"]));
                int mtid = int.Parse(this.ddltype.SelectedValue);

                decimal quota = decimal.Parse(this.txtquota.Text);


                lcs.Model.protocolquotainfo model = new lcs.Model.protocolquotainfo();
                model.mtid = mtid;
                model.quota = quota;
                model.pqid = pqid;
                lcs.BLL.protocolquotainfo bll = new lcs.BLL.protocolquotainfo();
                bll.Update(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");
            }

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
